package com.sixin.web.controller.iot;

import com.sixin.common.annotation.Log;
import com.sixin.common.base.AjaxResult;
import com.sixin.common.enums.BusinessType;
import com.sixin.common.page.TableDataInfo;
import com.sixin.common.utils.poi.ExcelUtil;
import com.sixin.framework.web.base.BaseController;
import com.sixin.iot.domain.Sandbox;
import com.sixin.iot.service.IISandboxService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/iot/sandbox")
public class SandboxController extends BaseController {
    private String prefix = "iot/sandbox";
    @Autowired
    private IISandboxService IISandboxService;

    @RequiresPermissions("iot:sandinfo:view")
    @GetMapping()
    public String Sandbox() {
        return prefix + "/sandbox";
    }

    /**
     * Sandbox列表
     *
     * @param Sandbox
     * @return
     */
    @RequiresPermissions("iot:sandinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Sandbox sandbox) {
        startPage();
        List<Sandbox> list = IISandboxService.selectSandboxList(sandbox);
        return getDataTable(list);
    }

    /**
     * 导出Sandbox列表
     */
    @Log(title = "Sandbox", businessType = BusinessType.EXPORT)
    @RequiresPermissions("iot:sandboxinfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Sandbox sandbox) {
        List<Sandbox> list = IISandboxService.selectSandboxList(sandbox);
        ExcelUtil<Sandbox> util = new ExcelUtil<Sandbox>(Sandbox.class);
        return util.exportExcel(list, "sandbox");
    }
    /**
     * 新增
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增 Sandbox信息
     */
    @RequiresPermissions("iot:sandinfo:add")
    @Log(title = " Sandbox信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Sandbox sandbox) {
        return toAjax(IISandboxService.insertSandbox(sandbox));
    }

    /**
     * 修改 Sandbox信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Sandbox sandbox = IISandboxService.selectByid(id);
        mmap.put("sandbox", sandbox);
        return prefix + "/edit";
    }

    /**
     * 修改保存 Sandbox信息
     */
    @RequiresPermissions("iot:sandinfo:edit")

    @Log(title = " Sandbox信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Sandbox sandbox) {
        return toAjax(IISandboxService.updateSandbox(sandbox));
    }
    /**
     * 修改用户状态
     */
    @RequiresPermissions("iot:sandinfo:edit")

    @Log(title = " 用户状态", businessType = BusinessType.UPDATE)
    @PostMapping("/changeDelflag")
    @ResponseBody
    public AjaxResult changeDelflag(Sandbox sandbox) {
        return toAjax(IISandboxService.changeDelflag(sandbox));
    }


    /**
     * 删除 Sandbox信息
     */
    @RequiresPermissions("iot:sandinfo:remove")
    @Log(title = "删除 Sandbox信息", businessType = BusinessType.DELETE)

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        //  System.out.println("*******"+id);
        return toAjax(IISandboxService.deleteSandboxByids(ids));
    }
}